/* 
 * File:   ComparadorGroundTruth.cpp
 * Author: Henrique
 * 
 * Created on 11 de Novembro de 2011, 10:37
 */

#include "ComparadorGroundTruth.h"

ComparadorGroundTruth::ComparadorGroundTruth() {
}

ComparadorGroundTruth::ComparadorGroundTruth(const ComparadorGroundTruth& orig) {
}

ComparadorGroundTruth::~ComparadorGroundTruth() {
}

double ComparadorGroundTruth::verificarQualidade(const char * esperado, Conteudo* encontrado) {

    ifstream archieve(esperado);

    string file = "GT.txt";
    Auxiliar::createArchieve(file, encontrado->toString());
    ifstream answer(file.c_str());

    int right = 0;
    int wrong = 0;

    char answerLine[200];
    char archieveLine[200];

    while (true) {
        if (answer.eof()) {
            break;
        }
        archieve.getline(archieveLine, 200);
        answer.getline(answerLine, 200);

        while (strcmp(answerLine, "") != 0) {
            answer.getline(answerLine, 200);
            archieve.getline(archieveLine, 200);
            if (strcmp(answerLine, "") != 0) {
                if (strcmp(answerLine, archieveLine) == 0) {
                    right++;
                } else {
                    wrong++;
                    
                }
            }
        }
    }
    archieve.close();
    answer.close();

    int total = right + wrong;
    double hitRate = (double) right / (double) total;
    return hitRate;
}



